<?php

namespace app\api\controller;

use app\api\logic\DulizhanLogic;
use think\facade\Db;

class DulizhanPackage
{
    /**
     * @desc  整理货号跟件数
     */
    public function AddSKUDetails(){
        $t1       = microtime(true);
        $count = Db::connect('DULIZHAN')
            ->name('order')
            ->where('created_at',">",1704038400)
            ->where('skuinfo_time',"=",0)
            ->order('created_at desc')
            ->count();
        $pageSize = 500; // 每500条记录读取一次
        $page     = ceil($count / $pageSize);
        $executedCount = 0;
        for ($i = 1; $i <= $page; $i++){
            $list = Db::connect('DULIZHAN')
                ->name('order')
                ->field('id')
                ->where('created_at',">",1704038400)
                ->where('skuinfo_time',"=",0)
                ->order('created_at desc')
                ->paginate($pageSize)
                ->toArray();
            foreach ($list as $v){
                (new DulizhanLogic())->AddSKUDetails($v);
                $executedCount++;
                $num = $count - $executedCount;
                echo PHP_EOL . "总计:" . $count . '条' . '-----' . "已执行:" . $executedCount . '-----' . '剩余:' . $num . '条' . PHP_EOL;
            }
        }
        echo PHP_EOL . "get_webhook_infos-定时执行总耗时:" . round(microtime(true) - $t1, 3) . PHP_EOL;
    }
    /**
     * @desc  整理订单是否被结算
     */
    public function HasTheOrderBeenSettled(){
        $t1       = microtime(true);
        $count = Db::connect('DULIZHAN')
            ->name('jiesuan')
            ->where('status',"=",null)
            ->count();
        $pageSize = 500; // 每500条记录读取一次
        $page     = ceil($count / $pageSize);
        $executedCount = 0;
        for ($i = 1; $i <= $page; $i++){
            $list = Db::connect('DULIZHAN')
                ->name('jiesuan')
                ->field('order_id')
                ->where('status',"=",null)
                ->paginate($pageSize)
                ->toArray();
            foreach ($list['data'] as $v){
                (new DulizhanLogic())->HasTheOrderBeenSettled($v);
                $executedCount++;
                $num = $count - $executedCount;
                echo PHP_EOL . "总计:" . $count . '条' . '-----' . "已执行:" . $executedCount . '-----' . '剩余:' . $num . '条' . PHP_EOL;
            }
        }
        echo PHP_EOL . "get_webhook_infos-定时执行总耗时:" . round(microtime(true) - $t1, 3) . PHP_EOL;
    }



}
